home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / os2 / freetype.zip / olddbg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-09-07  |  10.6 KB  |  536 lines

  1. (* The first text-mode version of the debugger. It seems to work though .. *)
  2.  
  3. program TTDEBUG;
  4.  
  5. uses Crt, TTTypes, TTError, TTTables, TTFile, TTIns;
  6.  
  7. type
  8.   PShort = ^Int16;
  9.   PLong  = ^Long;
  10.  
  11.   ByteHexStr  = string[2];    (* hex representation of a byte  *)
  12.   ShortHexStr = string[4];    (*  "        "          "  short *)
  13.   LongHexStr  = string[8];    (*  "        "          "  long  *)
  14.   DebugStr    = string[128];  (* disassembled line output      *)
  15.  
  16.   PStorageLong = ^TStorageLong;
  17.   TStorageLong = record       (* do-it-all union record type *)
  18.            case Byte of
  19.             0 : ( L     : LongInt );
  20.             1 : ( S1, S2 : Integer );
  21.             2 : ( W1, W2 : Word );
  22.             3 : ( B1, B2,
  23.               B3, B4 : Byte );
  24.             4 : ( P     : Pointer );
  25.           end;
  26.  
  27. var
  28.   FileName    : String;
  29.   Font_Buffer : PStorage;
  30.   Out_File    : Text;
  31.   T, I          : int;
  32.  
  33.   OpSize : int;
  34.  
  35. const
  36.   OpStr : array[ 0..255 ] of String[10]
  37.     = (
  38.         'SVTCA  y',      (* Set vectors to coordinate axis y    *)
  39.         'SVTCA  x',      (* Set vectors to coordinate axis x    *)
  40.         'SPvTCA y',      (* Set Proj. vec. to coord. axis y     *)
  41.         'SPvTCA x',      (* Set Proj. vec. to coord. axis x     *)
  42.         'SFvTCA y',      (* Set Free. vec. to coord. axis y     *)
  43.         'SFvTCA x',      (* Set Free. vec. to coord. axis x     *)
  44.         'SPvTL //',      (* Set Proj. vec. parallel to segment  *)
  45.         'SPvTL +',         (* Set Proj. vec. normal to segment    *)
  46.         'SFvTL //',      (* Set Free. vec. parallel to segment  *)
  47.         'SFvTL +',         (* Set Free. vec. normal to segment    *)
  48.         'SPvFS',         (* Set Proj. vec. from stack        *)
  49.         'SFvFS',         (* Set Free. vec. from stack        *)
  50.         'GPV',         (* Get projection vector            *)
  51.         'GFV',         (* Get freedom vector            *)
  52.         'SFvTPv',         (* Set free. vec. to proj. vec.        *)
  53.         'ISECT',         (* compute intersection            *)
  54.  
  55.         'SRP0',         (* Set reference point 0            *)
  56.         'SRP1',         (* Set reference point 1            *)
  57.         'SRP2',         (* Set reference point 2            *)
  58.         'SZP0',         (* Set Zone Pointer 0            *)
  59.         'SZP1',         (* Set Zone Pointer 1            *)
  60.         'SZP2',         (* Set Zone Pointer 2            *)
  61.         'SZPS',         (* Set all zone pointers            *)
  62.         'SLOOP',         (* Set loop counter            *)
  63.         'RTG',         (* Round to grid                *)
  64.         'RTHG',         (* Round to half grid            *)
  65.         'SMD',         (* Set Minimum Distance            *)
  66.         'ELSE',         (* Else                    *)
  67.         'JMPR',         (* Jump Relative                *)
  68.         'SCvTCi',         (* Set CVT                 *)
  69.         'SSwCi',         (*                     *)
  70.         'SSW',         (*                     *)
  71.  
  72.         'DUP',
  73.         'POP',
  74.         'CLEAR',
  75.         'SWAP',
  76.         'DEPTH',
  77.         'CINDEX',
  78.         'MINDEX',
  79.         'AlignPTS',
  80.         'INS_$28',
  81.         'UTP',
  82.         'LOOPCALL',
  83.         'CALL',
  84.         'FDEF',
  85.         'ENDF',
  86.         'MDAP[0]',
  87.         'MDAP[1]',
  88.  
  89.         'IUP[0]',
  90.         'IUP[1]',
  91.         'SHP[0]',
  92.         'SHP[1]',
  93.         'SHC[0]',
  94.         'SHC[1]',
  95.         'SHZ[0]',
  96.         'SHZ[1]',
  97.         'SHPIX',
  98.         'IP',
  99.         'MSIRP[0]',
  100.         'MSIRP[1]',
  101.         'AlignRP',
  102.         'RTDG',
  103.         'MIAP[0]',
  104.         'MIAP[1]',
  105.  
  106.         'NPushB',
  107.         'NPushW',
  108.         'WS',
  109.         'RS',
  110.         'WCvtP',
  111.         'RCvt',
  112.         'GC[0]',
  113.         'GC[1]',
  114.         'SCFS',
  115.         'MD[0]',
  116.         'MD[1]',
  117.         'MPPEM',
  118.         'MPS',
  119.         'FlipON',
  120.         'FlipOFF',
  121.         'DEBUG',
  122.  
  123.         'LT',
  124.         'LTEQ',
  125.         'GT',
  126.         'GTEQ',
  127.         'EQ',
  128.         'NEQ',
  129.         'ODD',
  130.         'EVEN',
  131.         'IF',
  132.         'EIF',
  133.         'AND',
  134.         'OR',
  135.         'NOT',
  136.         'DeltaP1',
  137.         'SDB',
  138.         'SDS',
  139.  
  140.         'ADD',
  141.         'SUB',
  142.         'DIV',
  143.         'MUL',
  144.         'ABS',
  145.         'NEG',
  146.         'FLOOR',
  147.         'CEILING',
  148.         'ROUND[0]',
  149.         'ROUND[1]',
  150.         'ROUND[2]',
  151.         'ROUND[3]',
  152.         'NROUND[0]',
  153.         'NROUND[1]',
  154.         'NROUND[2]',
  155.         'NROUND[3]',
  156.  
  157.         'WCvtF',
  158.         'DeltaP2',
  159.         'DeltaP3',
  160.         'DeltaCn[0]',
  161.         'DeltaCn[1]',
  162.         'DeltaCn[2]',
  163.         'SROUND',
  164.         'S45Round',
  165.         'JROT',
  166.         'JROF',
  167.         'ROFF',
  168.         'INS_$7B',
  169.         'RUTG',
  170.         'RDTG',
  171.         'SANGW',
  172.         'AA',
  173.  
  174.         'FlipPT',
  175.         'FlipRgON',
  176.         'FlipRgOFF',
  177.         'INS_$83',
  178.         'INS_$84',
  179.         'ScanCTRL',
  180.         'SDVPTL[0]',
  181.         'SDVPTL[1]',
  182.         'GetINFO',
  183.         'IDEF',
  184.         'ROLL',
  185.         'MAX',
  186.         'MIN',
  187.         'ScanTYPE',
  188.         'IntCTRL',
  189.         'INS_$8F',
  190.  
  191.         'INS_$90',
  192.         'INS_$91',
  193.         'INS_$92',
  194.         'INS_$93',
  195.         'INS_$94',
  196.         'INS_$95',
  197.         'INS_$96',
  198.         'INS_$97',
  199.         'INS_$98',
  200.         'INS_$99',
  201.         'INS_$9A',
  202.         'INS_$9B',
  203.         'INS_$9C',
  204.         'INS_$9D',
  205.         'INS_$9E',
  206.         'INS_$9F',
  207.  
  208.         'INS_$A0',
  209.         'INS_$A1',
  210.         'INS_$A2',
  211.         'INS_$A3',
  212.         'INS_$A4',
  213.         'INS_$A5',
  214.         'INS_$A6',
  215.         'INS_$A7',
  216.         'INS_$A8',
  217.         'INS_$A9',
  218.         'INS_$AA',
  219.         'INS_$AB',
  220.         'INS_$AC',
  221.         'INS_$AD',
  222.         'INS_$AE',
  223.         'INS_$AF',
  224.  
  225.         'PushB[0]',
  226.         'PushB[1]',
  227.         'PushB[2]',
  228.         'PushB[3]',
  229.         'PushB[4]',
  230.         'PushB[5]',
  231.         'PushB[6]',
  232.         'PushB[7]',
  233.         'PushW[0]',
  234.         'PushW[1]',
  235.         'PushW[2]',
  236.         'PushW[3]',
  237.         'PushW[4]',
  238.         'PushW[5]',
  239.         'PushW[6]',
  240.         'PushW[7]',
  241.  
  242.         'MDRP[00]',
  243.         'MDRP[01]',
  244.         'MDRP[02]',
  245.         'MDRP[03]',
  246.         'MDRP[04]',
  247.         'MDRP[05]',
  248.         'MDRP[06]',
  249.         'MDRP[07]',
  250.         'MDRP[08]',
  251.         'MDRP[09]',
  252.         'MDRP[10]',
  253.         'MDRP[11]',
  254.         'MDRP[12]',
  255.         'MDRP[13]',
  256.         'MDRP[14]',
  257.         'MDRP[15]',
  258.         'MDRP[16]',
  259.         'MDRP[17]',
  260.  
  261.         'MDRP[18]',
  262.         'MDRP[19]',
  263.         'MDRP[20]',
  264.         'MDRP[21]',
  265.         'MDRP[22]',
  266.         'MDRP[23]',
  267.         'MDRP[24]',
  268.         'MDRP[25]',
  269.         'MDRP[26]',
  270.         'MDRP[27]',
  271.         'MDRP[28]',
  272.         'MDRP[29]',
  273.         'MDRP[30]',
  274.         'MDRP[31]',
  275.  
  276.         'MIRP[00]',
  277.         'MIRP[01]',
  278.         'MIRP[02]',
  279.         'MIRP[03]',
  280.         'MIRP[04]',
  281.         'MIRP[05]',
  282.         'MIRP[06]',
  283.         'MIRP[07]',
  284.         'MIRP[08]',
  285.         'MIRP[09]',
  286.         'MIRP[10]',
  287.         'MIRP[11]',
  288.         'MIRP[12]',
  289.         'MIRP[13]',
  290.         'MIRP[14]',
  291.         'MIRP[15]',
  292.         'MIRP[16]',
  293.         'MIRP[17]',
  294.  
  295.         'MIRP[18]',
  296.         'MIRP[19]',
  297.         'MIRP[20]',
  298.         'MIRP[21]',
  299.         'MIRP[22]',
  300.         'MIRP[23]',
  301.         'MIRP[24]',
  302.         'MIRP[25]',
  303.         'MIRP[26]',
  304.         'MIRP[27]',
  305.         'MIRP[28]',
  306.         'MIRP[29]',
  307.         'MIRP[30]',
  308.         'MIRP[31]'
  309.      );
  310.  
  311. const
  312.   HexStr : string[16] = '0123456789ABCDEF';
  313.  
  314.  
  315. (**********)
  316. (*  Hex8  *)
  317. (**********)
  318.  
  319. function Hex8( B : Byte ) : ByteHexStr;
  320. var
  321.   S : ByteHexStr;
  322. begin
  323.   S[0] :=#2;
  324.   S[1] := HexStr[ 1+( B shr 4 ) ];
  325.   S[2] := HexStr[ 1+( B and 15 )];
  326.   Hex8 := S;
  327. end;
  328.  
  329. (***********)
  330. (*  Hex16  *)
  331. (***********)
  332.  
  333. function Hex16( W : word ) : ShortHexStr;
  334. begin
  335.   Hex16 := Hex8( Hi(w) )+Hex8( Lo(w) );
  336. end;
  337.  
  338. (***********)
  339. (*  Hex32  *)
  340. (***********)
  341.  
  342. function Hex32( L : Long ) : LongHexStr;
  343. begin
  344.   Hex32 := Hex16( TStorageLong(L).W2 )+Hex16( TStorageLong(L).W1 );
  345. end;
  346.  
  347. (****************)
  348. (*  Cur_U_Line    *)
  349. (****************)
  350.  
  351. function Cur_U_Line : DebugStr;
  352. var
  353.   Op   : Byte;
  354.   N, I : Int;
  355.   S    : DebugStr;
  356. begin
  357.  
  358.   Op := Code^[IP];
  359.   S  := '$'+Hex16(IP)+': '+Hex8(Op)+'  '+OpStr[Op];
  360.  
  361.   case Op of
  362.  
  363.     $40 : begin
  364.        n := Code^[IP+1];
  365.        S := S+'('+Hex8(n)+')';
  366.        for i := 1 to n do
  367.          S := S+' $'+Hex8( Code^[Ip+i+1] );
  368.       end;
  369.  
  370.     $41 : begin
  371.        n := Code^[IP+1];
  372.        S := S+'('+Hex8(n)+')';
  373.        for i := 1 to n do
  374.          S := S+' $'+Hex8( Code^[Ip+i*2+1] )+Hex8( Code^[Ip+i*2+2] );
  375.       end;
  376.  
  377.     $B0..$B7 : begin
  378.          n := Op-$B0;
  379.          for i := 0 to N do
  380.            S := S+' $'+Hex8( Code^[Ip+i+1] );
  381.            end;
  382.  
  383.     $B8..$BF : begin
  384.          n := Op-$B8;
  385.          for i := 0 to N do
  386.            S := S+' $'+Hex8( Code^[IP+i*2+1] )+Hex8( Code^[Ip+i*2+2] );
  387.            end;
  388.  
  389.   end;
  390.  
  391.   Cur_U_Line := S;
  392. end;
  393.  
  394. procedure Do_Line;
  395. begin
  396. (*  writeln( Out_File,Cur_U_Line ); *)
  397.   if not Run then
  398.     begin
  399.        Writeln('ERREUR : ', Error );
  400.       halt(1);
  401.     end;
  402. end;
  403.  
  404.  
  405.  
  406.  
  407. var
  408.   Range : Int;
  409.   P    : Pointer;
  410.  
  411. begin
  412.   TextMode( co80+Font8x8 );
  413.  
  414.   GetMem( Font_Buffer, 64000 );
  415.  
  416.   InitBuffer( Font_Buffer^, 64000 );
  417.  
  418.   for i:=0 to ParamCount do Writeln(ParamStr(i));
  419.  
  420.   If paramCount<>1 then
  421.    begin
  422.     Writeln('Usage : ',paramStr(0),' FontName[.TTF]');
  423.     Halt(1);
  424.    end;
  425.  
  426.   Filename := ParamStr(1);
  427.   if Pos('.',FileName)=0 then FileName:=FileName+'.TTF';
  428.   if not Open_TrueType_File( Filename ) then
  429.    begin
  430.     Writeln('Erreur, le fichier ',ParamStr(1),' n''a pu être ouvert');
  431.     Halt(1);
  432.    end;
  433.  
  434.   Load_TrueType_Tables;
  435.  
  436.   if not Load_TrueType_MaxProfile then
  437.    begin
  438.     Writeln('Erreur, la table ''maxp'' est introuvable');
  439.     Halt(1);
  440.    end;
  441.  
  442.   if not Load_TrueType_CVT then
  443.    begin
  444.     Writeln('Erreur, la table ''cvt '' est introuvable');
  445.     Halt(1);
  446.    end;
  447.  
  448.   if not Load_TrueType_Header then
  449.    begin
  450.     Writeln('Erreur, l''en-tête est introuvable');
  451.     Halt(1);
  452.    end;
  453.  
  454.   SetScale( 14, 96, Font_Header^.UnitsPerEM );
  455.  
  456.   if not Init_Interpreter( MaxProfile ) then
  457.     begin
  458.       Writeln('Erreur, initialisation interpréteur');
  459.       Halt(1);
  460.     end;
  461.  
  462.   T := LookUp_TrueType_Table('fpgm');
  463.  
  464.   if T < 0 then
  465.     begin
  466.       Writeln('FONT table not found');
  467.       halt(1);
  468.     end;
  469.  
  470.   Assign( Out_File,'' );
  471.   Rewrite( Out_File );
  472.  
  473.   Writeln( Out_File,'Font Program Offset :', Table_Dir_Entries^[T].Offset );
  474.   Writeln( Out_File,'Font Program Size     :', Table_Dir_Entries^[T].Length );
  475.  
  476.   CodeSize := Table_Dir_Entries^[T].Length;
  477.  
  478.   P := Alloc_CodeRange( Codesize, Range );
  479.   if P = nil then
  480.    begin
  481.      writeln('Erreur, impossible d''allouer le font program' );
  482.      halt(1);
  483.    end;
  484.  
  485.   writeln( Out_File,'------- FONT -------');
  486.   Read_At_Font_File( Table_Dir_Entries^[T].Offset,
  487.              P^, CodeSize );
  488.  
  489.   if not Goto_CodeRange( Range, 0 ) then
  490.    begin
  491.     writeln('Erreur, référence invalide');
  492.     Halt(1);
  493.    end;
  494.  
  495.   Instruction_Trap := True;
  496.  
  497.   while IP < CodeSize do
  498.    DO_Line;
  499.  
  500.   writeln( Out_File,'------- CVT -------');
  501.   T := LookUp_TrueType_Table('prep');
  502.  
  503.   if T < 0 then
  504.     begin
  505.       Writeln('PREP table not found');
  506.       halt(1);
  507.     end;
  508.  
  509.   Writeln( Out_File,'CVT Program Offset :', Table_Dir_Entries^[T].Offset );
  510.   Writeln( Out_File,'CVT Program Size    :', Table_Dir_Entries^[T].Length );
  511.  
  512.   CodeSize := Table_Dir_Entries^[T].Length;
  513.  
  514.   P := Alloc_CodeRange( Codesize, Range );
  515.   if P = nil then
  516.    begin
  517.      writeln('Erreur, impossible d''allouer le CVT program' );
  518.      halt(1);
  519.    end;
  520.  
  521.   Read_At_Font_File( Table_Dir_Entries^[T].Offset,
  522.              P^, CodeSize );
  523.  
  524.   if not Goto_CodeRange( Range, 0 ) then
  525.    begin
  526.     writeln('Erreur, référence invalide');
  527.     Halt(1);
  528.    end;
  529.  
  530.   while IP < CodeSize do
  531.    DO_Line;
  532.  
  533.   writeln('-----------------------');
  534.  
  535. end.
  536.